

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import net.miginfocom.swing.MigLayout;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Color;
import javax.swing.JPasswordField;
import javax.swing.JFormattedTextField;

import javax.swing.border.LineBorder;

public class alert extends JDialog {

	private final JPanel contentPanel = new JPanel();

	/**
	 * Launch the application.
	 */
/*	public static void main(String[] args) {
		try {
			LoginDialog dialog = new LoginDialog(main);
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}*/

	/**
	 * Create the dialog.
	 * @param aNr 
	 */
	public alert(String errorMsg) {
		getContentPane().setLayout(new MigLayout("", "[grow]", "[][]"));
		
		// Lese Laenge vom String aus
		int windowSize = errorMsg.length();
		
		JLabel lblError = new JLabel(errorMsg);
		getContentPane().add(lblError, "cell 0 0");
		
		// Mach ne gute Windowsize :)
		if(windowSize > 50) { windowSize = 500; }
		else { windowSize = 300; }
		
		setBounds(100, 100, windowSize, 100);

		JPanel buttonPane = new JPanel();
		buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));

			JButton cancelButton = new JButton("Ok");
			cancelButton.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
					dispose();
				}
			});
			cancelButton.setActionCommand("Cancel");
			buttonPane.add(cancelButton);

		getContentPane().add(buttonPane, "cell 0 2,growx,aligny top");
		
		this.setModal(true);
        this.setAlwaysOnTop(true);
	}
}
